<script setup>
import { RouterLink, RouterView, useRoute, useRouter } from 'vue-router'
import { ref, computed, onMounted } from 'vue'
import PaymentModal from './components/PaymentModal.vue'

const route = useRoute()
const router = useRouter()

// 判断是否为欢迎页面
const isWelcomePage = computed(() => {
  return route.path === '/'
})

// 导航状态管理
const searchVisible = ref(false)
const mobileMenuVisible = ref(false)
const userMenuVisible = ref(false)

// 用户状态
const userInfo = ref(null)
const isLoggedIn = ref(false)

// 购物车商品数量
const cartItemCount = computed(() => {
  try {
    const cart = localStorage.getItem('shadowplayCart')
    if (cart) {
      const items = JSON.parse(cart)
      return items.reduce((count, item) => count + item.quantity, 0)
    }
  } catch (error) {
    console.error('Error reading cart:', error)
  }
  return 0
})

// 初始化用户状态
onMounted(() => {
  checkUserLoginStatus()
  // 将应用实例挂载到window对象，以便其他组件可以访问
  window.appInstance = { openPaymentModal: openPaymentModal }
})

// 检查用户登录状态
const checkUserLoginStatus = () => {
  const loginStatus = localStorage.getItem('isLoggedIn') === 'true' || sessionStorage.getItem('isLoggedIn') === 'true'
  isLoggedIn.value = loginStatus
  
  if (loginStatus) {
    const storedUserInfo = localStorage.getItem('userInfo')
    if (storedUserInfo) {
      userInfo.value = JSON.parse(storedUserInfo)
    }
  }
}

// 切换搜索框显示
const toggleSearch = () => {
  searchVisible.value = !searchVisible.value
  mobileMenuVisible.value = false
  userMenuVisible.value = false
}

// 切换移动端菜单显示
const toggleMobileMenu = () => {
  mobileMenuVisible.value = !mobileMenuVisible.value
  searchVisible.value = false
  userMenuVisible.value = false
}

// 切换用户菜单显示
const toggleUserMenu = () => {
  userMenuVisible.value = !userMenuVisible.value
  searchVisible.value = false
  mobileMenuVisible.value = false
}

// 关闭所有下拉菜单
const closeAllDropdowns = () => {
  searchVisible.value = false
  mobileMenuVisible.value = false
  userMenuVisible.value = false
}

// 退出登录
const logout = () => {
  // 清除登录状态
  localStorage.removeItem('isLoggedIn')
  sessionStorage.removeItem('isLoggedIn')
  localStorage.removeItem('userInfo')
  
  // 更新状态
  isLoggedIn.value = false
  userInfo.value = null
  userMenuVisible.value = false
  showPaymentModal.value = false
  
  // 跳转到登录页
  router.push('/login')
}

// 支付弹窗状态
const showPaymentModal = ref(false)
const selectedProduct = ref({
  id: '',
  name: '',
  price: 0,
  type: 'membership',
  details: ''
})

// 处理支付成功
const handlePaymentSuccess = (paymentResult) => {
  console.log('支付成功:', paymentResult)
  // 这里可以根据支付结果更新用户会员信息
  alert(`支付成功！订单号: ${paymentResult.orderId}`)
  
  // 如果是会员购买，更新用户等级
  if (paymentResult.product.type === 'membership' && isLoggedIn.value) {
    const storedUserInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    // 根据产品名称判断会员等级
    if (paymentResult.product.name.includes('学子')) {
      storedUserInfo.level = '学子会员'
    } else if (paymentResult.product.name.includes('传人')) {
      storedUserInfo.level = '传人会员'
    } else if (paymentResult.product.name.includes('大师')) {
      storedUserInfo.level = '大师会员'
    }
    // 设置过期时间（简单示例：30天后）
    const now = new Date()
    now.setDate(now.getDate() + 30)
    storedUserInfo.expiresDate = now.toISOString().split('T')[0]
    
    // 保存更新后的用户信息
    localStorage.setItem('userInfo', JSON.stringify(storedUserInfo))
    userInfo.value = storedUserInfo
  }
  
  // 如果是购票，添加到用户订单记录
  if (paymentResult.product.type === 'ticket') {
    let userOrders = JSON.parse(localStorage.getItem('userOrders') || '[]')
    userOrders.push({
      id: paymentResult.orderId,
      product: paymentResult.product,
      amount: paymentResult.amount,
      paymentMethod: paymentResult.paymentMethod,
      timestamp: paymentResult.timestamp,
      status: '已完成'
    })
    localStorage.setItem('userOrders', JSON.stringify(userOrders))
  }
  
  // 关闭支付弹窗
  showPaymentModal.value = false
}

// 获取头像文字
const getAvatarText = () => {
  if (userInfo.value && (userInfo.value.username || userInfo.value.phone)) {
    return (userInfo.value.username || userInfo.value.phone).charAt(0)
  }
  return '游'
}

// 打开支付弹窗
const openPaymentModal = (product) => {
  if (!isLoggedIn.value) {
    alert('请先登录后再购票')
    router.push('/login')
    return
  }
  
  // 设置产品类型为ticket
  product.type = 'ticket'
  selectedProduct.value = { ...product }
  showPaymentModal.value = true
}
</script>

<template>
  <div class="app-container">
    <!-- 欢迎页面单独显示 -->
    <template v-if="isWelcomePage">
      <RouterView />
    </template>
    
    <!-- 其他页面显示完整布局 -->
    <template v-else>
      <!-- 头部区域 -->
      <header class="header">
        <div class="header-bg">
          <div class="header-content">
            <h1 class="site-title">影韵华彩</h1>
            <p class="site-subtitle">探索中国传统艺术之美</p>
          </div>
        </div>
      </header>
      
      <!-- 导航窗格 -->
      <div class="navigation-wrapper" @click="closeAllDropdowns">
        <nav class="main-nav" @click.stop>
          <div class="nav-container">
            <div class="nav-left">
              <RouterLink to="/home" class="nav-logo">
                影韵华彩
                <span class="site-subtitle">皮影艺术数字博物馆</span>
              </RouterLink>
            </div>
            <div class="nav-center">
              <RouterLink to="/home" class="nav-item" active-class="active">首页</RouterLink>
              <span class="nav-divider">·</span>
              <RouterLink to="/about" class="nav-item" active-class="active">历史源流</RouterLink>
              <span class="nav-divider">·</span>
              <RouterLink to="/types" class="nav-item" active-class="active">地域流派</RouterLink>
              <span class="nav-divider">·</span>
              <RouterLink to="/artists" class="nav-item" active-class="active">皮影大师</RouterLink>
              <span class="nav-divider">·</span>
              <div class="nav-dropdown">
                <button class="nav-dropbtn">经典剧目</button>
                <div class="nav-dropdown-content">
                  <RouterLink to="/traditional-plays" class="dropdown-item">传统剧目</RouterLink>
                  <RouterLink to="/modern-adaptations" class="dropdown-item">现代改编</RouterLink>
                  <RouterLink to="/performance-calendar" class="dropdown-item">演出日历</RouterLink>
                </div>
              </div>
              <span class="nav-divider">·</span>
              <RouterLink to="/culture" class="nav-item" active-class="active">文化传承</RouterLink>
            </div>
            <div class="nav-right">
              <button class="nav-button search-button" @click="toggleSearch">🔍</button>
              <!-- 用户登录状态显示 -->
              <template v-if="isLoggedIn">
                <div class="user-profile" @click="toggleUserMenu">
                  <div class="user-avatar">
                    <span>{{ getAvatarText() }}</span>
                  </div>
                  <span class="username">{{ userInfo.username || userInfo.phone }}</span>
                  <span class="user-level">{{ userInfo.level || '普通会员' }}</span>
                  <span class="user-arrow">{{ userMenuVisible ? '▲' : '▼' }}</span>
                  
                  <!-- 用户菜单 -->
                  <div class="user-menu" :class="{ 'show': userMenuVisible }">
                    <RouterLink to="/membership" class="menu-item">会员中心</RouterLink>
                    <a href="#" class="menu-item">我的收藏</a>
                    <a href="#" class="menu-item">个人中心</a>
                    <a href="#" class="menu-item">我的订单</a>
                    <div class="menu-divider"></div>
                    <a href="#" class="menu-item logout" @click="logout">退出登录</a>
                  </div>
                </div>
              </template>
              <!-- 未登录状态显示 -->
              <template v-else>
                <RouterLink to="/login" class="nav-button login-button">登录</RouterLink>
                <RouterLink to="/register" class="nav-button register-button">注册</RouterLink>
              </template>
              <router-link to="/cart" class="nav-button cart-button">
                <span>🛒</span>
                <span v-if="cartItemCount > 0" class="cart-badge">{{ cartItemCount }}</span>
              </router-link>
              <!-- 移动端菜单按钮 -->
              <button class="nav-button mobile-menu-button" @click="toggleMobileMenu">☰</button>
            </div>
          </div>
        </nav>
        
        <!-- 搜索框（默认隐藏） -->
        <div class="search-box" :class="{ 'show': searchVisible }">
          <div class="search-wrapper">
            <span class="search-icon">🔍</span>
            <input type="text" placeholder="搜索皮影戏相关内容..." />
            <button class="search-submit">搜索</button>
          </div>
        </div>
        
        <!-- 移动端导航菜单（默认隐藏） -->
        <div class="mobile-menu" :class="{ 'show': mobileMenuVisible }">
          <div class="mobile-menu-content" @click.stop>
            <RouterLink to="/home" class="mobile-nav-item" @click="mobileMenuVisible = false">首页</RouterLink>
            <RouterLink to="/about" class="mobile-nav-item" @click="mobileMenuVisible = false">历史源流</RouterLink>
            <RouterLink to="/types" class="mobile-nav-item" @click="mobileMenuVisible = false">地域流派</RouterLink>
            <RouterLink to="/artists" class="mobile-nav-item" @click="mobileMenuVisible = false">皮影大师</RouterLink>
            <div class="mobile-dropdown">
              <button class="mobile-dropbtn">经典剧目</button>
              <div class="mobile-dropdown-content">
                <RouterLink to="/traditional-plays" class="dropdown-item mobile-dropdown-item" @click="mobileMenuVisible = false">传统剧目</RouterLink>
                  <RouterLink to="/modern-adaptations" class="dropdown-item mobile-dropdown-item" @click="mobileMenuVisible = false">现代改编</RouterLink>
                  <RouterLink to="/performance-calendar" class="dropdown-item mobile-dropdown-item" @click="mobileMenuVisible = false">演出日历</RouterLink>
              </div>
            </div>
            <RouterLink to="/culture" class="mobile-nav-item" @click="mobileMenuVisible = false">文化传承</RouterLink>
            <div class="mobile-user-actions">
              <template v-if="isLoggedIn">
                <div class="mobile-user-info">
                  <div class="user-avatar-small">
                    <span>{{ getAvatarText() }}</span>
                  </div>
                  <span class="username">{{ userInfo.username || userInfo.phone }}</span>
                  <span class="user-level-small">{{ userInfo.level || '普通会员' }}</span>
                  <div class="mobile-user-menu">
                    <RouterLink to="/membership" class="menu-item" @click="mobileMenuVisible = false">会员中心</RouterLink>
                    <a href="#" class="menu-item">我的收藏</a>
                    <a href="#" class="menu-item logout" @click="logout">退出登录</a>
                  </div>
                </div>
              </template>
              <template v-else>
                <RouterLink to="/login" class="mobile-nav-button">登录</RouterLink>
                <RouterLink to="/register" class="mobile-nav-button">注册</RouterLink>
              </template>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 主要内容区域 -->
      <main class="main-content">
        <RouterView />
      </main>
      
      <!-- 页脚 -->
      <footer class="footer">
        <div class="footer-content">
          <div class="footer-info">
            <p>© 2024 皮影戏 - 中国非物质文化遗产保护中心</p>
            <p>传承中华文化，弘扬民族艺术</p>
          </div>
          <div class="footer-contact">
            <p>电话：(+86) 123-4567-8910</p>
            <p>邮箱：info@piyingxi.com</p>
          </div>
        </div>
        <div class="footer-bottom">
          <p>地址：中国北京市东城区东直门外大街42号</p>
        </div>
      </footer>
    </template>
  </div>
  
  <!-- 支付弹窗组件 -->
  <PaymentModal 
    :show="showPaymentModal"
    :product="selectedProduct"
    :user-level="userInfo?.level || '游客'"
    @close="showPaymentModal = false"
    @payment-success="handlePaymentSuccess"
  />
</template>

<style scoped>
/* CSS变量定义 */
:root {
  --color-primary: #9d2933; /* 故宫红 */
  --color-secondary: #d4af37; /* 帝王金 */
  --color-background: #f5f1e6; /* 宣纸米白 */
  --color-text-dark: #333333; /* 深灰 */
  --color-text-medium: #666666; /* 中灰 */
  --color-white: #ffffff;
  --color-accent: var(--color-primary);
  --c-paper: #f8f3e6;
  --color-background-soft: #f5f1e6;
}

/* 全局样式重置和通用设置 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 应用容器 */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* 皮影戏风格的装饰边框 - 全局 */
.app-container::before {
  content: '';
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  bottom: 20px;
  border: 2px solid var(--color-accent);
  opacity: 0.1;
  pointer-events: none;
  z-index: -1;
}

/* 头部样式 - 皮影戏风格 */
.header {
  position: relative;
  height: 500px;
  overflow: hidden;
  background-color: var(--c-paper);
}

/* 皮影戏传统色彩渐变背景 */
.header-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, rgba(166, 36, 36, 0.9), rgba(46, 67, 116, 0.8));
  opacity: 0.9;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 皮影戏风格的纹理装饰 */
.header-bg::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('');
  background-size: 300px 300px;
  opacity: 0.1;
  z-index: 1;
}

/* 皮影戏风格的装饰边框 */
.header-bg::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  border: 2px solid var(--color-accent);
  opacity: 0.3;
  pointer-events: none;
}

.header-content {
  text-align: center;
  color: white;
  z-index: 2;
  animation: fadeIn 1.5s ease-in-out;
  background: rgba(0, 0, 0, 0.5);
  padding: 2rem;
  border-radius: 8px;
  backdrop-filter: blur(10px);
  max-width: 800px;
}

.site-title {
  font-size: 3.5rem;
  margin: 0;
  color: var(--color-secondary);
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.6);
  font-family: 'STZhongsong', 'SimSun', serif;
  letter-spacing: 4px;
  font-weight: bold;
  position: relative;
  display: inline-block;
}

/* 皮影戏标题装饰 */
.site-title::before,
.site-title::after {
  content: '❖';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  color: var(--color-secondary);
  opacity: 0.8;
}

.site-title::before {
  left: -2rem;
}

.site-title::after {
  right: -2rem;
}

.site-subtitle {
  font-size: 1.3rem;
  margin-top: 0.5rem;
  color: var(--color-white);
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 2px;
  opacity: 0.95;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  font-style: italic;
}

/* 导航窗格样式 - 传统卷轴风格 */
.navigation-wrapper {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--color-primary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  border-bottom: 2px solid var(--color-secondary);
  background-image: linear-gradient(to right, transparent, var(--color-primary), transparent);
}

/* 导航装饰 */
.navigation-wrapper::before,
.navigation-wrapper::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 3px;
  background-image: linear-gradient(to right, transparent, var(--color-secondary), transparent);
}

.navigation-wrapper::before {
  top: 0;
}

.navigation-wrapper::after {
  bottom: -5px;
}

.main-nav {
  background-color: var(--color-primary);
}

.nav-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  max-width: 1200px;
  margin: 0 auto;
  height: 60px;
}

.nav-left, .nav-center, .nav-right {
  display: flex;
  align-items: center;
}

/* 导航Logo */
.nav-logo {
  color: var(--color-secondary);
  font-size: 1.5rem;
  font-weight: bold;
  text-decoration: none;
  font-family: 'STZhongsong', 'SimSun', serif;
  padding: 0 1.5rem;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.nav-logo:hover {
  color: #f0c14b;
  transform: scale(1.05);
}

.site-subtitle {
  color: var(--color-secondary);
  font-size: 0.8rem;
  font-weight: normal;
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 1px;
  margin-top: 2px;
  opacity: 0.9;
}

/* 中心导航项 */
.nav-center {
  flex: 1;
  justify-content: center;
  gap: 0.5rem;
  display: flex;
  align-items: center;
}

.nav-item {
  color: var(--color-secondary);
  padding: 1rem 0.8rem;
  font-size: 16px;
  font-weight: normal;
  text-decoration: none;
  position: relative;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 0.5px;
}

.nav-item:hover {
  color: #f0c14b;
  background: rgba(212, 175, 55, 0.1);
  border-radius: 4px;
}

.nav-item.active {
  color: #f0c14b;
  background: rgba(212, 175, 55, 0.2);
  border-radius: 4px;
}

/* 导航分隔符 */
.nav-divider {
  color: var(--color-secondary);
  padding: 1rem 0.2rem;
  font-size: 16px;
  opacity: 0.6;
}

/* 下拉菜单 */
.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropbtn {
  background: none;
  border: none;
  color: var(--color-secondary);
  padding: 1rem 0.8rem;
  font-size: 16px;
  font-weight: normal;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 0.5px;
}

.nav-dropbtn:hover {
  color: #f0c14b;
  background: rgba(212, 175, 55, 0.1);
  border-radius: 4px;
}

.nav-dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  z-index: 1;
  border-radius: 4px;
}

.nav-dropdown-content .dropdown-item {
  color: var(--color-text-dark);
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  transition: background-color 0.3s ease;
  font-size: 14px;
  font-family: 'STKaiti', 'KaiTi', serif;
}

.nav-dropdown-content .dropdown-item:hover {
  background-color: var(--color-background-soft);
  color: var(--color-primary);
}

.nav-dropdown-content a:hover {
  background-color: var(--color-background-soft);
}

.nav-dropdown:hover .nav-dropdown-content {
  display: block;
}

/* 右侧用户功能区 */
.nav-right {
  gap: 0.5rem;
}

.nav-button {
  background: none;
  border: none;
  color: var(--color-secondary);
  padding: 0.6rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  position: relative;
}

.cart-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: #D4AF37;
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  line-height: 1.2;
}

.nav-button:hover {
  background-color: rgba(212, 175, 55, 0.1);
  color: #f0c14b;
}

.login-button, .register-button {
  border: 1px solid var(--color-secondary);
  padding: 0.4rem 1rem;
  font-family: 'STKaiti', 'KaiTi', serif;
}

.register-button {
  background-color: var(--color-secondary);
  border-color: var(--color-secondary);
  color: var(--color-primary);
  font-weight: bold;
}

.register-button:hover {
  background-color: #f0c14b;
  border-color: #f0c14b;
  color: var(--color-primary);
}

/* 用户状态样式 */
.user-profile {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
  background-color: #f5f1e6;
}

.user-profile:hover {
  background-color: #e8dfcf;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background-color: #9d2933;
  color: white;
  border: 2px solid #d4af37;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  margin-right: 8px;
}

.username {
  font-size: 14px;
  color: var(--color-text-dark);
  margin-right: 8px;
}

.user-level {
  font-size: 12px;
  color: #d4af37;
  background-color: rgba(212, 175, 55, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 8px;
}

.user-arrow {
  font-size: 12px;
  color: var(--color-text-medium);
  transition: transform 0.3s;
}

/* 用户菜单 */
.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s;
  z-index: 1000;
}

.user-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.menu-item {
  display: block;
  padding: 12px 20px;
  color: var(--color-text-dark);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.3s;
}

.menu-item:hover {
  background-color: #f5f1e6;
  color: #9d2933;
}

.menu-item.logout:hover {
  background-color: #ffebee;
  color: #9d2933;
}

.menu-divider {
  height: 1px;
  background-color: #eee;
  margin: 4px 0;
}

/* 移动端用户信息 */
.mobile-user-info {
  padding: 16px;
  background-color: #f5f1e6;
  border-radius: 8px;
  margin-bottom: 16px;
}

.user-avatar-small {
  width: 40px;
  height: 40px;
  background-color: #9d2933;
  color: white;
  border: 2px solid #d4af37;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 8px;
}

.username {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-dark);
  margin-bottom: 4px;
}

.user-level-small {
  font-size: 12px;
  color: #d4af37;
}

.mobile-user-menu {
  margin-top: 16px;
}

.mobile-user-menu .menu-item {
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}

.mobile-user-menu .menu-item:last-child {
  border-bottom: none;
}

/* 移动端菜单按钮（默认隐藏） */
.mobile-menu-button {
  display: none;
}

/* 搜索框样式 */
.search-box {
  display: none;
  background-color: var(--color-white);
  padding: 1rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-box.show {
  display: block;
}

.search-wrapper {
  position: relative;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background-color: white;
  border-radius: 25px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.search-icon {
  position: absolute;
  left: 15px;
  font-size: 16px;
  color: var(--color-text-medium);
  z-index: 1;
}

.search-box input {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 40px;
  border: none;
  border-radius: 25px 0 0 25px;
  font-size: 14px;
  outline: none;
  color: var(--color-text-dark);
}

.search-submit {
  width: 100px;
  padding: 0.8rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: 0 25px 25px 0;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  font-weight: bold;
}

.search-submit:hover {
  background-color: #a82727;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 移动端菜单样式 */
.mobile-menu {
  display: none;
  background-color: var(--color-white);
  position: absolute;
  width: 100%;
  top: 60px;
  left: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 999;
  border-top: 1px solid #e0e0e0;
}

.mobile-menu.show {
  display: block;
}

.mobile-menu-content {
  padding: 1rem;
}

.mobile-nav-item {
  display: block;
  color: var(--color-text-dark);
  padding: 1rem;
  text-decoration: none;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 0.5px;
  font-size: 16px;
}

.mobile-nav-item:hover {
  color: var(--color-primary);
  background: rgba(198, 47, 47, 0.05);
  padding-left: 1.2rem;
}

.mobile-dropdown {
  position: relative;
}

.mobile-dropbtn {
  width: 100%;
  background: none;
  border: none;
  color: var(--color-text-dark);
  padding: 1rem;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-dropbtn:hover {
  color: var(--color-primary);
  background: rgba(198, 47, 47, 0.05);
}

.mobile-dropdown-content {
  display: none;
  padding-left: 2rem;
  background-color: #f9f9f9;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 200px;
  }
}

.mobile-dropdown-content a {
  display: block;
  color: var(--color-text-dark);
  padding: 0.8rem;
  text-decoration: none;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
  font-size: 14px;
}

.mobile-dropdown-content a:hover {
  color: var(--color-primary);
  padding-left: 1rem;
}

.mobile-dropdown:hover .mobile-dropdown-content {
  display: block;
}

.mobile-user-actions {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
}

.mobile-nav-button {
  flex: 1;
  padding: 0.8rem;
  border: 1px solid var(--color-primary);
  background: none;
  color: var(--color-text-dark);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.3s ease;
  font-family: 'STKaiti', 'KaiTi', serif;
}

.mobile-nav-button:last-child {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.mobile-nav-button:hover {
  color: var(--color-primary);
  background: rgba(198, 47, 47, 0.05);
}

.mobile-nav-button:last-child:hover {
  background-color: #a82727;
  border-color: #a82727;
  color: white;
}

/* 主内容区域 */
.main-content {
  min-height: 500px;
  background-color: var(--color-background-soft);
}

/* 页脚样式 */
.footer {
  background-color: #f5f5f5;
  color: var(--color-text-dark);
  padding: 2rem 0;
  border-top: 2px solid var(--color-secondary);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.footer-info,
.footer-contact {
  flex: 1;
}

.footer-bottom {
  margin-top: 2rem;
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.9rem;
}

.footer a {
  color: var(--color-primary);
  text-decoration: none;
}

.footer a:hover {
  color: #a82727;
  text-decoration: underline;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .nav-logo {
    font-size: 1.3rem;
    padding: 0 1rem;
  }
  
  .nav-item, .nav-dropbtn {
    padding: 1rem 0.8rem;
    font-size: 14px;
  }
  
  
  .nav-button {
    padding: 0.5rem 0.8rem;
  }
}

@media (max-width: 768px) {
  .header {
    height: 300px;
  }
  
  .site-title {
    font-size: 20px;
  }
  
  .site-subtitle {
    font-size: 13px;
  }
  
  /* 隐藏桌面端导航 */
  .nav-center {
    display: none;
  }
  
  /* 显示移动端菜单按钮 */
  .mobile-menu-button {
    display: flex;
  }
  
  /* 简化右侧用户功能区 */
  .login-button, .register-button {
    display: none;
  }
  
  /* 调整搜索框样式 */
  .search-wrapper {
    border-radius: 20px;
  }
  
  .search-icon {
    left: 12px;
    font-size: 14px;
  }
  
  .search-box input {
    padding: 0.7rem 0.8rem 0.7rem 35px;
    border-radius: 20px 0 0 20px;
    font-size: 13px;
  }
  
  .search-submit {
    width: 70px;
    padding: 0.7rem 0.5rem;
    border-radius: 0 20px 20px 0;
    font-size: 13px;
  }
  
  /* 页脚样式调整 */
  .footer-content {
    flex-direction: column;
    padding: 0 1rem;
  }
  
  .footer-info,
  .footer-contact {
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 480px) {
  .header {
    height: 250px;
  }
  
  .site-title {
    font-size: 18px;
  }
  
  .site-subtitle {
    font-size: 12px;
  }
  
  .nav-container {
    padding: 0 0.5rem;
  }
  
  .nav-logo {
    font-size: 1.1rem;
    padding: 0 0.5rem;
  }
  
  .nav-button {
    padding: 0.5rem;
    font-size: 0.9rem;
  }
}
</style>
